package com.duoduo.demo.springnoxml.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.duoduo.demo.springnoxml.service.AppService;

@RestController
public class AppController {

	@Autowired
	private AppService appService;

	@RequestMapping("/")
	public String home() {
		return "Hello World!";
	}

	@RequestMapping("/hello/{myName}")
	public String index(@PathVariable String myName) {
		return "Hello " + myName + "!!!";
	}

	@RequestMapping("/ajax/array")
	@ResponseBody
	public Object ajaxArray() {
		Object[] array = new Object[] {
				1, "陈小生", 9.78f
		};
		return array;
	}

	@RequestMapping("/ajax/map")
	@ResponseBody
	public Object ajaxMap() {
		Map<String, Object> map = new HashMap<String, Object>(0);
		map.put("id", 1);
		map.put("name", "陈小生");
		map.put("score", 9.78f);
		return map;
	}

	@RequestMapping("/ajax/list")
	@ResponseBody
	public Object ajaxList() {
		List<Object> list = new ArrayList<Object>(0);
		list.add(1);
		list.add("陈小生");
		list.add(9.78f);
		return list;
	}

	@RequestMapping("/app/info")
	@ResponseBody
	public Object appInfo() {
		appService.showSystemInfo();
		return appService.getSystemInfo();
	}

}
